﻿using System.Text;

namespace SHA_SuRe
{
    class Helper
    {
        public static byte[] StringToArrayByte(string s)
        {
            int length = s.Length;
            byte[] bytes = new byte[length];

            for (int i = 0; i < length; ++i)
            {
                bytes[i] = (byte)s[i];
            }

            return bytes;
        }

        public static string ArrayByteToString(byte[] bytes)
        {
            int length = bytes.Length;
            StringBuilder sb = new StringBuilder(length);
            char[] chars;

            // To chars
            chars = ArrayByteToArrayChar(bytes);

            // copy to string builder
            sb.Append(chars);

            return sb.ToString();
        }

        private static char[] ArrayByteToArrayChar(byte[] bytes)
        {
            int length = bytes.Length;
            char[] chars = new char[length];

            for (int i = 0; i < length; ++i)
            {
                chars[i] = (char)bytes[i];
            }

            return chars;
        }
    }
}
